﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Zhaoxi.AnimationLesson
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // 对象Border：宽度：1秒：从100变化200
            // 1、确定需要变化对象的属性的类型
            //double
            DoubleAnimation doubleAnimation = new DoubleAnimation();
            doubleAnimation.Duration = new TimeSpan(0, 0, 1);
            doubleAnimation.From = 100;
            doubleAnimation.To = 200;


            // 动画对象的默认帧率  （每秒钟变化次数）：60帧
            // 可调 120    1

            // 动画需要作用在对象的依赖属性上的，普通属性不可以



            ThicknessAnimation thicknessAnimation = new ThicknessAnimation();
            thicknessAnimation.Duration = new TimeSpan(0, 0, 1);
            thicknessAnimation.From = new Thickness(-200, 0, 0, 0);
            thicknessAnimation.To = new Thickness(0);

            //this.border.BeginAnimation(Border.WidthProperty, doubleAnimation);
            //this.left_border.BeginAnimation(Border.MarginProperty, thicknessAnimation);


            // 这两个动画同步执行的吗？还是有先后的
            // 如果需要动画执行不能有差异，需要同时开始


            Storyboard storyboard = new Storyboard();
            // 将需要的故事线（动画对象）放到一个舞台（故事板）
            storyboard.Children.Add(doubleAnimation);
            storyboard.Children.Add(thicknessAnimation);

            // 关联对象
            Storyboard.SetTarget(doubleAnimation, this.border);
            Storyboard.SetTarget(thicknessAnimation, this.left_border);
            // 关联属性
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));

            storyboard.Begin();


            // 1、使用了简单的动画对象，从某个状态到中一个状态的过程，中间不做其他变化 
            // 2、C#语言实现动画的过程



            // 获取窗口资源   ：sb    -》 Storkboard-》进行启动
            // WPF按钮的动作不写到窗口后台，绑定命令
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Clip = this.clipPath.Data;
        }
    }
}